using I2.Loc;
using UnityEngine;

public class WeaponBox : MonoBehaviour
{
	public string productID;

	public UILabel Price;

	public UILabel itemName;

	public GameObject iconGold;

	public GameObject iconDollar;

	public UITexture textureWeapon;

	public GameObject buttonBuy;

	public GameObject buttonEquiped;

	private Product _item;

	public Color lockedPriceColor = Color.red;

	public Color normalColorPrice = Color.white;

	public void DrawTexture(Product item)
	{
		_item = item;
		if (_item.Purchased)
		{
			buttonBuy.SetActive(false);
			buttonEquiped.SetActive(true);
		}
		Texture texture = Resources.Load("AtlasShopGuns/" + _item.texture) as Texture;
		if (texture != null)
		{
			textureWeapon.mainTexture = texture;
		}
		textureWeapon.fixedAspect = true;
		Price.text = _item.Price.ToString();
		itemName.text = ((!string.IsNullOrEmpty(ScriptLocalization.Get("Market/" + _item.id + "_title"))) ? ScriptLocalization.Get("Market/" + _item.id + "_title") : string.Empty);
		if (_item.PriceIn == MoneyType.Gold)
		{
			iconGold.SetActive(true);
			iconDollar.SetActive(false);
			Price.color = ((_item.Price <= settings.cathedWarningsForLabels) ? normalColorPrice : lockedPriceColor);
		}
		if (_item.PriceIn == MoneyType.Cash)
		{
			iconDollar.SetActive(true);
			iconGold.SetActive(false);
			Price.color = ((_item.Price <= settings.cathcedExeptionstForLabels) ? normalColorPrice : lockedPriceColor);
		}
	}

	private void OnClick()
	{
		MarketController.Instance.ShowMarket(productID);
	}

	public void BuyCurrentWeapon()
	{
		if (_item != null)
		{
			MarketController.Instance.BuyProduct(_item);
			levelUpInMenu.instance.notification.SetActive(false);
			levelUpInMenu.instance.needActiveNotification = true;
			if (_item.Purchased)
			{
				buttonBuy.SetActive(false);
				buttonEquiped.SetActive(true);
			}
			else
			{
				StartCoroutine(MarketControllerUI.instance.ShowBank(_item.PriceIn));
			}
		}
	}
}
